﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebsiteLab2.MasterPages
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        private List<string> categories;
        private List<OurServices.Product> products;
        private string categoriesID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                LoadCategories();

                // Get init state categories;
                categoriesID = this.DropDownList1.Items[DropDownList1.SelectedIndex].Value;

                LoadProducts(categoriesID);
            }
        }

        protected void LoadCategories(){
            categories = WebsiteLab2.BUS.ProductBUS.getAllTypesByServices();
            this.DropDownList1.DataSource = categories;
            this.DropDownList1.DataBind();
            this.DropDownList1.SelectedIndex = 0;
        }

        protected void LoadProducts(string categoriesID){
            products = WebsiteLab2.BUS.ProductBUS.getAllProductsByTypesServices(categoriesID);
            this.GridView1.DataSource = products;
            this.GridView1.DataBind();
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            categoriesID = this.DropDownList1.Items[DropDownList1.SelectedIndex].Value;

            LoadProducts(categoriesID);
        }

    }
}
